package com.myapp.ruyixing.ui.shopmanager;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.myapp.ruyixing.R;
import com.myapp.ruyixing.ui.DiscountActivity;
import com.myapp.ruyixing.ui.FoodListActivity;
import com.myapp.ruyixing.ui.RankActivity;
import com.myapp.ruyixing.ui.ScoreMallActivity;
import com.myapp.ruyixing.ui.SearchCityActivity;
import com.myapp.ruyixing.utils.LoginHelper;

public class ShopManagerMainFragment extends Fragment implements
		OnClickListener {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_shop_manager_main, container,
				false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);

		view.findViewById(R.id.search_city).setOnClickListener(this);
		view.findViewById(R.id.search_top).setOnClickListener(this);
		view.findViewById(R.id.layout_food).setOnClickListener(this);
		view.findViewById(R.id.layout_discount).setOnClickListener(this);
		view.findViewById(R.id.nearby_scoreshop).setOnClickListener(this);

		view.findViewById(R.id.manage_activity).setOnClickListener(this);
		view.findViewById(R.id.manage_appraisal).setOnClickListener(this);
		view.findViewById(R.id.manage_impression).setOnClickListener(this);
		view.findViewById(R.id.manage_order).setOnClickListener(this);
		view.findViewById(R.id.manage_shop).setOnClickListener(this);

		view.findViewById(R.id.log_out).setOnClickListener(this);

		loadData();
	}

	private void loadData() {
		((TextView) getView().findViewById(R.id.shop_name)).setText("商户名称："
				+ LoginHelper.getInstance().getShopName());
		((TextView) getView().findViewById(R.id.city_name)).setText("所在城市："
				+ LoginHelper.getInstance().getShopCityName());
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.search_city:
			startActivity(new Intent(getActivity(), SearchCityActivity.class));

			break;
		case R.id.search_top:
			startActivity(new Intent(getActivity(), RankActivity.class));
			break;

		case R.id.layout_food:
			startActivity(new Intent(getActivity(), FoodListActivity.class));
			break;
		case R.id.nearby_scoreshop:
			startActivity(new Intent(getActivity(), ScoreMallActivity.class));
			break;
		case R.id.layout_discount:
			startActivity(new Intent(getActivity(), DiscountActivity.class));
			break;

		case R.id.manage_impression:
			startActivity(new Intent(getActivity(),
					ImpressionManageActivity.class));

			break;
		case R.id.manage_appraisal:
			startActivity(new Intent(getActivity(),
					AppraisalManageActivity.class));

			break;
		case R.id.manage_activity:
			startActivity(new Intent(getActivity(),
					ActivityManageActivity.class));

			break;
		case R.id.manage_shop:
			startActivity(new Intent(getActivity(), ShopManageActivity.class));

			break;
		case R.id.manage_order:
			startActivity(new Intent(getActivity(), OrderManageActivity.class));

			break;
		case R.id.log_out:
			LoginHelper.getInstance().doShopLogout();
			Intent intent = new Intent(getActivity(), LoginActivity.class);
			startActivity(intent);
			getActivity().finish();
			break;

		default:
			break;
		}
	}
}
